const Joi = require('joi');
const schema = {
    username: Joi.string().min(2).max(20).required().error(new Error('username验证错误')) ,
    birth: Joi.number().min(1900).max(2021).error(new Error('birth验证失败'))
}

async function run() {
    try {
        await Joi.validate({ username: '陈伟东', birth: 1999 }, schema);
    } catch (err) {
        console.log(err.message);
        return;
    }
    console.log('验证通过');
}

run();


